﻿using Quartz;

namespace 微信机器人服务.Quartz
{
    /// <summary>
    /// 
    /// </summary>
    public interface IQuartzJobsFactory
    {
        /// <summary>
        /// 检查存在
        /// </summary>
        /// <param name="jobKey"></param>
        /// <returns></returns>
        Task<bool> CheckExistsAsync(JobKey jobKey);
        /// <summary>
        /// 检查存在
        /// </summary>
        /// <param name="JobName"></param>
        /// <returns></returns>
        Task<bool> CheckExistsAsync(string JobName);
        /// <summary>
        /// 创建工作
        /// </summary>
        /// <param name="JobName"></param>
        /// <param name="timeSpan"></param>
        /// <param name="repeatTime"></param>
        /// <returns></returns>
        Task<bool> CreateJobAsync(string JobName, TimeSpan timeSpan, int repeatTime);
        /// <summary>
        /// 创建工作
        /// </summary>
        /// <param name="JobName"></param>
        /// <param name="cronExpression"></param>
        /// <param name="keyValuePair"></param>
        /// <returns></returns>
        Task<bool> CreateJobAsync(string JobName, string cronExpression, KeyValuePair<string, object> keyValuePair);

        /// <summary>
        /// 创建工作
        /// </summary>
        /// <param name="jobName"></param>
        /// <param name="cronExpression"></param>
        /// <returns></returns>
        Task<bool> CreateJobAsync(string jobName, string cronExpression);

        /// <summary>
        /// 创建一次性工作
        /// </summary>
        /// <param name="jobName"></param>
        /// <param name="runTime"></param>
        /// <returns></returns>
        Task<bool> CreateJobAsync(string jobName, DateTimeOffset runTime);
        /// <summary>
        /// 创建一次性任务并传参
        /// </summary>
        /// <param name="jobName"></param>
        /// <param name="runTime"></param>
        /// <param name="jobParams"></param>
        /// <returns></returns>
        Task<bool> CreateJobAsync(string jobName, DateTimeOffset runTime, IDictionary<string, object> jobParams);
        /// <summary>
        /// 创建工作
        /// </summary>
        /// <param name="jobName"></param>
        /// <param name="millisecond">毫秒</param>
        /// <returns></returns>
        Task<bool> CreateJobAsync(string jobName, int millisecond);
        /// <summary>
        /// 创建工作
        /// </summary>
        /// <param name="JobName">工作名称</param>
        /// <param name="timeSpan"></param>
        /// <param name="repeatTime"> 任务中断后的重启频率</param>
        /// <param name="keyValuePair">注入参数 属性名+注入的值 </param>
        /// <returns></returns>
        Task<bool> CreateJobAsync(string JobName, TimeSpan timeSpan, int repeatTime, KeyValuePair<string, object> keyValuePair);


        /// <summary>
        /// 获取所有可用作业名称
        /// </summary>
        /// <returns></returns>
        IEnumerable<string> GetAllAvailableJobName();
        /// <summary>
        /// 获取IJob的类扩展
        /// </summary>
        /// <returns></returns>
        IEnumerable<Type> GetClassExtendOfIJob();
        /// <summary>
        /// 按名称获取IJob的类扩展
        /// </summary>
        /// <param name="jobName"></param>
        /// <returns></returns>
        Type GetClassExtendOfIJobByName(string jobName);
        /// <summary>
        /// 通过名称获取工作密钥
        /// </summary>
        /// <param name="jobName"></param>
        /// <returns></returns>
        Task<JobKey> GetJobKeyByNameAsync(string jobName);
        /// <summary>
        /// 通过名称获取触发键
        /// </summary>
        /// <param name="triggerKeyName"></param>
        /// <returns></returns>
        Task<TriggerKey> GetTriggerKeyByNameAsync(string triggerKeyName);
        /// <summary>
        /// 获取工作触发器
        /// </summary>
        /// <param name="jobKey"></param>
        /// <returns></returns>
        Task<IReadOnlyCollection<ITrigger>> GetTriggersOfJobAsync(JobKey jobKey);
        /// <summary>
        /// 获取工作触发器
        /// </summary>
        /// <param name="jobName"></param>
        /// <returns></returns>
        Task<IReadOnlyCollection<ITrigger>?> GetTriggersOfJobAsync(string jobName);
        /// <summary>
        /// 获取触发状态
        /// </summary>
        /// <param name="triggerKey"></param>
        /// <returns></returns>
        Task<TriggerState> GetTriggerStateAsync(TriggerKey triggerKey);
        /// <summary>
        /// 暂停所有
        /// </summary>
        /// <returns></returns>
        Task PauseAllAsync();
        /// <summary>
        /// 暂停工作
        /// </summary>
        /// <param name="jobKey"></param>
        /// <returns></returns>
        Task PauseJobAsync(JobKey jobKey);
        /// <summary>
        /// 暂停工作
        /// </summary>
        /// <param name="jobName"></param>
        /// <returns></returns>
        Task PauseJobAsync(string jobName);
        /// <summary>
        /// 暂停工作
        /// </summary>
        /// <param name="triggerKey"></param>
        /// <returns></returns>
        Task PauseTriggerAsync(TriggerKey triggerKey);
        /// <summary>
        /// 暂停工作
        /// </summary>
        /// <param name="triggerKeyName"></param>
        /// <returns></returns>
        Task PauseTriggerAsync(string triggerKeyName);
        /// <summary>
        /// 恢复全部
        /// </summary>
        /// <returns></returns>
        Task ResumeAllAsync();
        /// <summary>
        /// 恢复工作
        /// </summary>
        /// <param name="jobKey"></param>
        /// <returns></returns>
        Task ResumeJobAsync(JobKey jobKey);
        /// <summary>
        /// 恢复工作
        /// </summary>
        /// <param name="jobName"></param>
        /// <returns></returns>
        Task ResumeJobAsync(string jobName);
        /// <summary>
        /// 恢复触发
        /// </summary>
        /// <param name="triggerKey"></param>
        /// <returns></returns>
        Task ResumeTriggerAsync(TriggerKey triggerKey);
        /// <summary>
        /// 恢复触发
        /// </summary>
        /// <param name="triggerKeyName"></param>
        /// <returns></returns>
        Task ResumeTriggerAsync(string triggerKeyName);
    }
}
